<template>
	<view class="unitRegisterThree">
		<view class="unitRegisterThree-header-state ff-align-items ff-text-center">
			<view class="unitRegisterThree-header-state-box">
				<image class="ff-margin-bottom-6"
					src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/step-1.png" mode="">
				</image>
				<view class="ff-font-12">员工信息</view>
			</view>
			<view class="unitRegisterThree-header-state-line"></view>
			<view class="unitRegisterThree-header-state-box">
				<image class="ff-margin-bottom-6"
					src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/step-1.png" mode="">
				</image>
				<view class="ff-font-12">完成，待审核</view>
			</view>
		</view>
		<view class="unitRegisterThree-content ff-bg-fff ff-border-radius-15 ff-text-center">
			<image src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/reg-success1.png" mode="">
			</image>
			<view class="ff-font-16 ff-margin-bottom-10">您的账号处于<text class="ff-color-blue">【待审核】</text>状态</view>
			<view class="ff-font-16 ff-line-height-1-3">请及时联系“{{ companyName }}”的管理员进行审核。</view>
		</view>
		<view class="unitRegisterThree-but">
			<view class="unitRegisterTwo-content-but-box"><u-button type="primary" shape="circle"
					@click="goLogin">刷新</u-button></view>
		</view>
		<f-loading ref="loading" />
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		encrypt
	} from '@/tools/sm.js'
	export default {
		name: 'unitRegisterThree',
		data() {
			return {
				companyName: ''
			};
		},
		onLoad(e) {
			this.companyName = e.companyName;
		},
		onShow() {
			uni.hideHomeButton(); // 隐藏小房子
		},
		methods: {
			// 去登录
			async goLogin() {
				this.$refs.loading.openLoading('请求中···');
				const res = await this.$http.post({
					url: '/loginASD',
					data: {
						param: encrypt(uni.getStorageSync('asdPhone'))
					}
				})
				if (res.code == 200 && res.success && res.data.multipleUsers !== null) {
					this.multiAccountLogin(params) // 多账号登录
				} else if (res.code == 200 && res.success) {
					this.setUserInfo(res.data.user); // 登录后获取的用户信息
					this.loginHandle(res.data.user); // 去登录
				} else if (res.code == 5101) {
					uni.showModal({
						title: '温馨提示',
						content: res.msg,
						confirmColor: '#3178FF',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {}
						}
					})
				} else {
					uni.showModal({
						title: '温馨提示',
						content: res.msg,
						confirmColor: '#3178FF',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {}
						}
					})
				}
				this.$refs.loading.closeLoading(); // 定义loadingTxt内容
			},
			// 多账号登录(账号密码)
			multiAccountLogin(e) {
				// console.log('多账号登录的信息列表--------', e);
				this.multiList = e.multipleUsers; // 账号列表赋值
				this.multiState = true; // 打开多账号登录弹框
			},
			// 多账号登录------选择某一个人员登录
			multiClick(item) {
				this.loginSelectId = item.id;
				this.$refs.loading.openLoading('登录中···');
				this.$http
					.post({
						url: '/multipleLoginASD',
						data: {
							param: encrypt(item.id)
						}
					})
					.then(res => {
						// console.log('多账号登录返回的数据---------', res);
						if (res.code == 200 && res.success) {
							this.setUserInfo(res.data.user); // 登录后获取的用户信息
							this.loginHandle(res.data.user); // 登录成功后判断人员类型
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}
						this.$refs.loading.closeLoading();
					});
			},
			// 登录后赋值操作
			loginHandle(uerInfo) {
				let userType = uerInfo.userType; // 1:监管人员  5:单位用户  8:维保人员  10:技术人员
				switch (userType) {
					case 1: // 监管人员
						// hasOwnProperty() 方法会返回一个布尔值，指示对象自身属性中是否具有指定的属性
						if (uerInfo.superviseStaff != null && uerInfo.hasOwnProperty('superviseStaff')) {
							// status：(0:未审核 1:已审核 5:已禁用)
							// staffType：(1:救援机构负责人, 2:救援机构专家 ,3:救援机构人员)
							let status = uerInfo.superviseStaff.status;
							let staffType = uerInfo.superviseStaff.staffType;
							if (status == 0) {
								//未审核
								uni.showModal({
									title: '温馨提示',
									content: '您的账号处于待审核状态，请联系您的单位确认审核后再登录！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 5) {
								//已禁用
								uni.showModal({
									title: '温馨提示',
									content: '您的账号已被禁用，请联系管理员！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 1) {
								uni.setStorageSync('isUserState', true); // 登录状态
								//已审核
								switch (staffType) {
									case 1: // 监管管理员
										this.setRoleStatus(4);
										break;
									case 2: // 监管员工
									case 3:
										this.setRoleStatus(5);
										break;
									default:
										break;
								}
								this.$pageJump.reLaunch('/pages/supervise/index'); // 跳转到监管页面
							} else {
								uni.showModal({
									title: '温馨提示',
									content: '您没有登录权限！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							}
						} else {
							uni.showModal({
								title: '温馨提示',
								content: '请求服务失败，请及时联系管理员！',
								confirmColor: '#3178FF',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {}
								}
							})
						}

						break;
					case 5: // 单位
						if (uerInfo.companyStaff != null && uerInfo.hasOwnProperty('companyStaff')) {
							let status = uerInfo.companyStaff.status;
							let staffType = uerInfo.companyStaff.staffType;
							if (status == 0) {
								//未审核
								uni.showModal({
									title: '温馨提示',
									content: '您的账号处于待审核状态，请联系您的单位确认审核后再登录！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 5) {
								// 已禁用
								uni.showModal({
									title: '温馨提示',
									content: '您的账号已被禁用，请联系管理员！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 1) {
								uni.setStorageSync('isUserState', true); // 登录状态
								// 已审核
								switch (staffType) {
									case 1: // 管理员
										this.setRoleStatus('0');
										break;
									case 5: // 员工
										this.setRoleStatus(1);
										break;
									default:
										break;
								}
								this.$pageJump.reLaunch('/pages/homeCentral/Central'); // 跳转到中心页面
							} else {
								uni.showModal({
									title: '温馨提示',
									content: '您没有登录权限！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							}
						} else {
							uni.showModal({
								title: '温馨提示',
								content: '请求服务失败，请及时联系管理员！',
								confirmColor: '#3178FF',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {}
								}
							})
						}
						break;
					case 8: // 维保人员
						if (uerInfo.orgStaff != null && uerInfo.hasOwnProperty('orgStaff')) {
							//机构员工
							let status = uerInfo.orgStaff.status;
							let staffType = uerInfo.orgStaff.staffType;
							if (status == 0) {
								//未审核
								uni.showModal({
									title: '温馨提示',
									content: '您的账号处于待审核状态，请联系您的机构确认审核后再登录！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
								return;
							} else if (status == 5) {
								//已禁用
								uni.showModal({
									title: '温馨提示',
									content: '您的账号已被禁用，请联系管理员！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							} else if (status == 1) {
								uni.setStorageSync('isUserState', true); // 登录状态
								//已审核
								switch (staffType) {
									case 1: //管理员
										this.setRoleStatus(2);
										break;
									case 5: //员工
										this.setRoleStatus(3);
										break;
									default:
										break;
								}
								this.$pageJump.reLaunch('/pages/homeCentral/Central'); // 跳转到中心页面
							} else {
								uni.showModal({
									title: '温馨提示',
									content: '您没有登录权限！',
									confirmColor: '#3178FF',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							}
						} else {
							uni.showModal({
								title: '温馨提示',
								content: '请求服务失败，请及时联系管理员！',
								confirmColor: '#3178FF',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {}
								}
							})
						}
						break;
					case 10: //技术人员
						uni.showModal({
							title: '温馨提示',
							content: '技术人员服务暂未开放！',
							confirmColor: '#3178FF',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {}
							}
						})
						break;
					default:
						break;
				}
			}
		},
		onShareAppMessage() {
			return {
				title: '分享小程序给朋友',
				path: '/pages/homePage/Home'
			};
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #e6f2fe;
	}

	.unitRegisterThree {
		&-header-state {
			background-color: #e6f2fe;
			width: 100%;
			justify-content: space-between;
			padding: 50rpx 15%;
			color: #6d7c99;

			&-box {
				image {
					width: 50rpx;
					height: 50rpx;
				}

				.step-number {
					width: 40rpx;
					height: 40rpx;
				}
			}

			&-line {
				width: 99rpx;
				height: 10rpx;
				background: #d2e5fa;
			}
		}

		&-content {
			margin: 5%;
			padding: 130rpx 30rpx;

			image {
				width: 168rpx;
				height: 144rpx;
				margin-bottom: 100rpx;
			}

			.ff-font-16 {
				color: #323233;
			}
		}

		&-but {
			padding: 120rpx 0 130rpx;
			margin: 0 6%;
			width: 88%;
			text-align: center;

			/deep/.u-size-default {
				height: 90rpx !important;
				line-height: 90rpx !important;
			}
		}
	}
</style>